<template>
  <div class="head-container">
    <div class="crud-opts">
      <el-input v-model="paramBean.msgTitle" clearable placeholder="输入标题搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="sup_this.toQuery"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="sup_this.toQuery">搜索</el-button>
      <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="sup_this.resetQuery()">重置</el-button>
      <el-button
        v-permission="['SYS_ADMIN','SYSMSG_ALL','SYSMSG_CREATE','SYSMSG_CHANGE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="toAdd">新增</el-button>
      <el-button
        v-permission="['SYS_ADMIN','SYSMSG_ALL','SYSMSG_DELETE']"
        v-loading="deleteLoading"
        class="filter-item"
        size="mini"
        type="danger"
        icon="el-icon-delete"
        @click="doMultiDelete">删除</el-button>
      <el-button
        v-loading="deleteLoading"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-check"
        @click="doMultiRead">标识已读</el-button>
      <DataGridOpts :sup_this="sup_this" :search-enable="false" @refreshClick="refreshClick" @searchClick="searchClick">
        <app-link slot="right" to="/msg/historylist">
          <el-button
            size="mini"
            plain
            type="warning"
            icon="el-icon-view"
            title="查看历史消息"
          />
        </app-link>
      </DataGridOpts>
    </div>
  </div>
</template>

<script>
import sysMsg from '@/api/system/SysMsg'
import AppLink from '@/views/layout/components/Sidebar/Link'

export default {
  components: { AppLink },
  props: {
    paramBean: {
      type: Object,
      required: true
    },
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      deleteLoading: false,
      submitLoading: false,
      destoryLoading: false
    }
  },
  methods: {
    refreshClick() {
      this.sup_this.init()
    },
    searchClick() {
      this.sup_this.toggleSearch()
    },
    beforeCreate() {
    },
    doMultiRead() {
      const _this = this.sup_this
      const selectIds = []
      _this.selectedGridRows.forEach(row => {
        selectIds.push(row.id)
      })
      if (selectIds.length === 0) {
        this.$message({
          message: '请选择记录',
          type: 'warning'
        })
        return
      }
      this.deleteLoading = true
      const data = { idList: selectIds }
      sysMsg.postRequestByName('doRead', data).then(res => {
        this.deleteLoading = false
        _this.init()
      }).catch(err => {
        this.deleteLoading = false
        console.log(err)
      })
    },
    doMultiDelete() {
      const _this = this.sup_this
      _this.doMultiDelete(sysMsg.deleteUrl(), this)
    },
    toCopy() {
      const _this = this.sup_this
      const selectMainId = _this.getSelectMainId()
      if (!selectMainId) {
        return
      }
      const _thisForm = _this.$refs.form
      _thisForm.initDataOfBefore()
      _thisForm.copyData(selectMainId)
    },
    toAdd() {
      const _this = this.sup_this.$refs.form
      _this.initDataOfBefore()
      _this.addData()
    }
  }
}
</script>
